
package TransportesMarroquin;

import java.awt.Cursor;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioSystem;
import javax.swing.JOptionPane;


public class Llantas extends javax.swing.JFrame {
    
 static ResultSetTableModel tableModel;
  int cod;
   static String consulta = "SELECT * FROM Llanta WHERE cementerio like 'no'";
   String tipo= new String(),file;
   
  boolean borrar = false ;
  int codigo;
  String tipos;
  int cvehiculo; // variables de la seleccion  
  String pos;
  int row;
  boolean entro = false;
  javax.sound.sampled.Clip sonido;
  
      public Llantas(String con, String t,int cod) {
        this.consulta=con;
        initComponents();
       
        this.cod = cod;
        cd.setText(""+cod);
        n.setText(""+t);
      
    }
    public Llantas(String con) {
        this.consulta=con;
        initComponents();
       
    }

   


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        cd = new javax.swing.JLabel();
        n = new javax.swing.JLabel();
        lnum2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jButton3 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        trash = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(143, 0, 0));

        cd.setFont(new java.awt.Font("Tahoma", 1, 18));
        cd.setForeground(new java.awt.Color(255, 255, 255));
        cd.setText(" ");

        n.setFont(new java.awt.Font("Tahoma", 1, 18));
        n.setForeground(new java.awt.Color(255, 255, 255));
        n.setText(" ");

        lnum2.setFont(new java.awt.Font("Tahoma", 1, 18));
        lnum2.setForeground(new java.awt.Color(255, 255, 255));
        lnum2.setText("Llantas ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lnum2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 554, Short.MAX_VALUE)
                .addComponent(n)
                .addGap(21, 21, 21)
                .addComponent(cd)
                .addGap(87, 87, 87))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cd)
                    .addComponent(n)
                    .addComponent(lnum2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        try{
            tableModel = new ResultSetTableModel( consulta );
        }catch(Exception e){
            System.out.println("ERROR");
        }
        resultTable.setModel(tableModel);
        resultTable.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        resultTable.setSelectionBackground(new java.awt.Color(255, 255, 255));
        resultTable.setSelectionForeground(new java.awt.Color(0, 0, 0));
        resultTable.getTableHeader().setReorderingAllowed(false);
        resultTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                resultTableMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                resultTableMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                resultTableMouseReleased(evt);
            }
        });
        resultTable.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                resultTableMouseDragged(evt);
            }
        });
        jScrollPane1.setViewportView(resultTable);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/regresar.png"))); // NOI18N
        jButton3.setText("Regresar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/camion.png"))); // NOI18N
        jButton5.setText("Camiones");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/caberzal.png"))); // NOI18N
        jButton6.setText("Cabezales");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/furgoni.png"))); // NOI18N
        jButton7.setText("Furgones");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316283080_michelin_48.png"))); // NOI18N
        jButton10.setText("Cementerio ");
        jButton10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jButton10MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jButton10MouseExited(evt);
            }
        });
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316393209_mail_new.png"))); // NOI18N
        jButton9.setText("Correo");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316298596_print_16x16.gif"))); // NOI18N
        jButton8.setText("Imprimir");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        trash.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/empty.png"))); // NOI18N
        trash.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                trashMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                trashMouseExited(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(trash)))
                .addGap(10, 10, 10)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 611, Short.MAX_VALUE)
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton10, jButton5, jButton6, jButton7, jButton8, jButton9});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton5)
                        .addGap(11, 11, 11)
                        .addComponent(jButton6)
                        .addGap(11, 11, 11)
                        .addComponent(jButton7)
                        .addGap(11, 11, 11)
                        .addComponent(jButton10)
                        .addGap(11, 11, 11)
                        .addComponent(jButton8)
                        .addGap(11, 11, 11)
                        .addComponent(jButton9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 68, Short.MAX_VALUE)
                        .addComponent(trash)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)
                        .addGap(15, 15, 15))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE)
                        .addContainerGap())))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton10, jButton5, jButton6, jButton7, jButton8, jButton9});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void resultTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultTableMouseClicked
      
}//GEN-LAST:event_resultTableMouseClicked

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        dispose();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
       tipo="Camion";
        consulta = "Select * from llanta where tipo_vehiculo like 'Camion' AND cementerio like 'no'";
        try {
            
            tableModel = new ResultSetTableModel( consulta );
            resultTable.setModel(tableModel);
        } catch (SQLException ex) {
            Logger.getLogger(Gasto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Gasto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Gasto.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
     tipo="Cabezal";
        consulta = "Select * from llanta where tipo_vehiculo like 'Cabezal' AND cementerio like 'no'";
        try {
            
            tableModel = new ResultSetTableModel( consulta );
            resultTable.setModel(tableModel);
        } catch (SQLException ex) {
            Logger.getLogger(Gasto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Gasto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Gasto.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
       tipo="Furgon";
        consulta = "Select * from llanta where tipo_vehiculo like 'Furgon' AND cementerio like 'no'";
        try {
            
            tableModel = new ResultSetTableModel( consulta );
            resultTable.setModel(tableModel);
        } catch (SQLException ex) {
            Logger.getLogger(Gasto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Gasto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Gasto.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton10MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton10MouseEntered
       
}//GEN-LAST:event_jButton10MouseEntered

    private void jButton10MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton10MouseExited
      
}//GEN-LAST:event_jButton10MouseExited

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        Cementerio cem;
        cem = new Cementerio("SELECT * FROM Llanta where cementerio like 'si'");
        cem.setVisible(true);
        cem.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width-114, Toolkit.getDefaultToolkit().getScreenSize().height-107);
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        file=Archivo.TipoB("ListadoLlanta",tipo);
        Archivo.Abrir(file);
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        file=Archivo.TipoB("ListadoLlanta",tipo);
        Correo.EnviarArchivo(Inicio.usuario,file);
    }//GEN-LAST:event_jButton9ActionPerformed

    private void trashMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_trashMouseEntered
        if(borrar == true){
      entro = true;
      trash.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/full.png")));
}
    }//GEN-LAST:event_trashMouseEntered

    private void trashMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_trashMouseExited
      entro= false;   
      borrar = false;
        trash.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/empty.png")));
    }//GEN-LAST:event_trashMouseExited

    private void resultTableMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultTableMouseDragged
      if(borrar == true && entro == false){
          Toolkit tk = Toolkit.getDefaultToolkit();
                Image imagen = tk.getImage(System.getProperty ("user.dir")+"\\src\\Imagenes\\basura.png");     
                Point hotSpot = new Point(0,0);  
                Cursor cursor = tk.createCustomCursor(imagen, hotSpot, "basura");
                this.setCursor(cursor);
      }        // TODO add your handling code here:
    }//GEN-LAST:event_resultTableMouseDragged

    private void resultTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultTableMousePressed
        row = resultTable.rowAtPoint(evt.getPoint());
    
      borrar=true;
     
      // accion qee va hacer siempre 
      if (row > -1)
                {
                      
                      Object objeto = tableModel.getValueAt(row, 0);

                     String ja = objeto.toString();
                     codigo=Integer.parseInt(ja);
                     // leo el nombre
                     objeto = tableModel.getValueAt(row, 1);
                     tipos = objeto.toString();
                     
                     // leo el apellido 
                     objeto = tableModel.getValueAt(row, 2);
                     ja = objeto.toString();
                     cvehiculo=Integer.parseInt(ja);
                     
                     objeto = tableModel.getValueAt(row, 3);
                     pos = objeto.toString();
                     
                     

                }     
    }//GEN-LAST:event_resultTableMousePressed

    private void resultTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultTableMouseReleased
        // accion del release 
        if(borrar == true && entro == true){
                  try {
                sonido = null;
                sonido = AudioSystem.getClip();
                sonido.open(AudioSystem.getAudioInputStream(new File(System.getProperty("user.dir") + "\\src\\SonidosPractica\\basura.wav")));
                sonido.start();




            } catch (Exception e) {
                System.out.println("" + e);
            } // fin

               
                int messageType = JOptionPane.QUESTION_MESSAGE;
                String[] options = {"Continuar", "Cancelar"};
                int code = JOptionPane.showInternalOptionDialog(this.getContentPane(),
                        "¿Desea realmente borrar la llanta Codigo "+codigo+" del "+tipos+" No. "+cvehiculo+" ?", 
                         "Confirmación", 1, messageType, 
                         null, options, "Cancelar");
               
                    
               
               
               if(code==0){
                   
                   // proceso para eliminar una llanta 
                   CambioLlanta va = new CambioLlanta(codigo,tipos,cvehiculo,pos);
                   va.setVisible(true);
                  
               
                      // sonido 
                      
        
                          }
               else
                   if(code == 1){
                       
                   }
               borrar = false;
               entro=false;
               }
               
     trash.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/empty.png")));         
     borrar = false;
    }//GEN-LAST:event_resultTableMouseReleased

   
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
              
            
               
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel cd;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lnum2;
    private javax.swing.JLabel n;
    public static final javax.swing.JTable resultTable = new javax.swing.JTable(tableModel);
    private javax.swing.JLabel trash;
    // End of variables declaration//GEN-END:variables
}
